using System;
using System.Linq;
using System.Web.Configuration;
using Kiwi.Container.Application;

namespace Kiwi.Container.Web
{
    public class AspNetFramework : IFramework
    {
        #region IFramework Members

        public void Initialize()
        {
            var moduleSection = WebConfigurationManager.GetSection("system.web/httpModules") as HttpModulesSection;

            if (moduleSection != null)
            {
                if (moduleSection.Modules.Cast<HttpModuleAction>().Any(a =>
                                                                           {
                                                                               var type = Type.GetType(a.Type);
                                                                               return typeof (ContainerModule) == type;
                                                                           }))
                {
                    return;
                }
            }
            throw new ContainerConfigurationException(Resource.MissingContainerModuleRegistration);
        }

        #endregion
    }
}